tokenizer.js ➔ ... ➔ this.match   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
'use strict'
2
3
import crypto from 'crypto'
4
5
export class Tokenizer {
6
  constructor (secret) {
7
    this.cipher = undefined
8
    this.decipher = undefined
9
10
    this.encrypt = function (text) {
11
      let crypted = this.cipher.update(text, 'utf8', 'hex')
12
      crypted += this.cipher.final('hex')
13
      return crypted
14
    }
15
16
    this.decrypt = function (text) {
17
      let dec = this.decipher.update(text, 'hex', 'utf8')
18
      dec += this.decipher.final('utf8')
19
      return dec
20
    }
21
22
    this.match = function (token, text) {
23
      return this.decrypt(token) === text
24
    }
25
26
    this.cipher = crypto.createCipher('aes-256-cbc', secret)
27
    this.decipher = crypto.createDecipher('aes-256-cbc', secret)
28
  }
29
}
30
31
export const genToken = (secret) => {
32
  return new Tokenizer(secret)
33
}
34